#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp>

class BaseNode : public rclcpp::Node
{
public:
    BaseNode()
    : Node("base_control"),
      publisher_(this->create_publisher<std_msgs::msg::String>("/serial_write", 10)),
      timer_(this->create_wall_timer(
               std::chrono::seconds(1), std::bind(&BaseNode::timer_callback, this)))
    {
        // 构造函数中不需要其他初始化代码，因为定时器已经在这里创建了
    }

private:
    void timer_callback()
    {
        auto message = std_msgs::msg::String();
        message.data = "send cmd data";
        RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str());
        publisher_->publish(message);
    }

    rclcpp::TimerBase::SharedPtr timer_;
    rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
};

int main(int argc, char *argv[])
{
    rclcpp::init(argc, argv);
    rclcpp::spin(std::make_shared<BaseNode>());
    rclcpp::shutdown();
    return 0;
}